package com.datastructure.test.nextbigger;

import java.util.ArrayList;

public class NextBigger {

    public static void main(String[] args) {

    }

    public ArrayList<Integer> nextBigger (ArrayList<Integer> nums) {
        // write code here
        int size = nums.size();
        int length = size * 2;
        ArrayList<Integer> result = new ArrayList<>(length);
        for (int i = 0; i < length; i++) {
            result.add(nums.get(i%size));
        }
        for (int i = 0; i < nums.size(); i++) {
            nums.set(i,computeValue(nums.get(i),i+1,result));
        }
        return nums;
    }

    private Integer computeValue(int initValue,int i, ArrayList<Integer> result) {
        Integer temp;
        for (int j = i; j < result.size(); j++) {
            temp= result.get(j);
            if(j>i&&temp.equals(result.get(j-1))){
                continue;
            }
            if(temp>initValue){
                return temp;
            }
        }
        return -1;
    }
}
